package com.wsb.wetchat.controller;

import com.wsb.wetchat.service.app.BaseInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @author wang shaobo
 * @date 2022/6/17  10:03
 */
@RestController
public class WetChatHomeController {


    private static final Logger logger = LoggerFactory.getLogger(WetChatHomeController.class);

    @Autowired
    BaseInfoService baseInfoService;

    @GetMapping("/home")
    public String home(){

        ServletRequestAttributes servletRequestAttributes =  (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        String code = request.getParameter("code");

        System.out.println(request);


        logger.info("用户请求主页");


        return "welcome wetchat api";

    }


    @GetMapping("/wetchat/token")
    public String getToken(){
        logger.info("用户获取企业微信API,TOKEN");
        return baseInfoService.getAccessToken();

    }

}
